home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.border.LineBorder;
- import com.sun.java.swing.event.CellEditorListener;
- import com.sun.java.swing.event.ChangeEvent;
- import com.sun.java.swing.event.ListSelectionEvent;
- import com.sun.java.swing.event.ListSelectionListener;
- import com.sun.java.swing.event.TableColumnModelEvent;
- import com.sun.java.swing.event.TableColumnModelListener;
- import com.sun.java.swing.event.TableModelEvent;
- import com.sun.java.swing.event.TableModelListener;
- import com.sun.java.swing.plaf.TableUI;
- import com.sun.java.swing.table.DefaultTableCellRenderer;
- import com.sun.java.swing.table.DefaultTableColumnModel;
- import com.sun.java.swing.table.DefaultTableModel;
- import com.sun.java.swing.table.JTableHeader;
- import com.sun.java.swing.table.TableCellEditor;
- import com.sun.java.swing.table.TableCellRenderer;
- import com.sun.java.swing.table.TableColumn;
- import com.sun.java.swing.table.TableColumnModel;
- import com.sun.java.swing.table.TableModel;
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.LayoutManager;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.InputEvent;
- import java.awt.event.MouseEvent;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.Enumeration;
- import java.util.EventObject;
- import java.util.Hashtable;
- import java.util.Vector;
-
- public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible {
- public static final int AUTO_RESIZE_OFF = 0;
- public static final int AUTO_RESIZE_LAST_COLUMN = 1;
- public static final int AUTO_RESIZE_ALL_COLUMNS = 2;
- protected TableModel dataModel;
- protected TableColumnModel columnModel;
- protected ListSelectionModel selectionModel;
- protected JTableHeader tableHeader;
- protected int rowHeight;
- protected int rowMargin;
- protected Color gridColor;
- protected boolean showHorizontalLines;
- protected boolean showVerticalLines;
- protected int autoResizeMode;
- protected boolean autoCreateColumnsFromModel;
- protected Dimension preferredViewportSize;
- protected boolean rowSelectionAllowed;
- protected boolean cellSelectionEnabled;
- protected transient Component editorComp;
- protected transient TableCellEditor cellEditor;
- protected transient int editingColumn;
- protected transient int editingRow;
- protected transient Hashtable defaultRenderersByColumnClass;
- protected transient Hashtable defaultEditorsByColumnClass;
- protected Color selectionForeground;
- protected Color selectionBackground;
- static Class class$java$lang$Object;
- static Class class$java$lang$Boolean;
- static Class class$com$sun$java$swing$ImageIcon;
- static Class class$java$lang$Number;
-
- public JTable() {
- this((TableModel)null, (TableColumnModel)null, (ListSelectionModel)null);
- }
-
- public JTable(Object[][] rowData, Object[] columnNames) {
- this(new 1(rowData, columnNames));
- }
-
- public JTable(int numRows, int numColumns) {
- this(new DefaultTableModel(numRows, numColumns));
- }
-
- public JTable(TableModel dm) {
- this(dm, (TableColumnModel)null, (ListSelectionModel)null);
- }
-
- public JTable(TableModel dm, TableColumnModel cm) {
- this(dm, cm, (ListSelectionModel)null);
- }
-
- public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
- ((Container)this).setLayout((LayoutManager)null);
- if (cm == null) {
- cm = this.createDefaultColumnModel();
- this.autoCreateColumnsFromModel = true;
- }
-
- this.setColumnModel(cm);
- if (sm == null) {
- sm = this.createDefaultSelectionModel();
- }
-
- this.setSelectionModel(sm);
- if (dm == null) {
- dm = this.createDefaultDataModel();
- }
-
- this.setModel(dm);
- this.initializeLocalVars();
- this.updateUI();
- }
-
- public JTable(Vector rowData, Vector columnNames) {
- this(new 2(rowData, columnNames));
- }
-
- public void addColumn(TableColumn aColumn) {
- int modelColumn = aColumn.getModelIndex();
- String columnName = this.getModel().getColumnName(modelColumn);
- if (aColumn.getHeaderValue() == null) {
- aColumn.setHeaderValue(columnName);
- }
-
- this.getColumnModel().addColumn(aColumn);
- }
-
- public void addColumnSelectionInterval(int index0, int index1) {
- this.columnModel.getSelectionModel().addSelectionInterval(index0, index1);
- }
-
- public void addNotify() {
- super.addNotify();
- this.configureEnclosingScrollPane();
- }
-
- public void addRowSelectionInterval(int index0, int index1) {
- this.selectionModel.addSelectionInterval(index0, index1);
- }
-
- public void clearSelection() {
- this.columnModel.getSelectionModel().clearSelection();
- this.selectionModel.clearSelection();
- }
-
- public void columnAdded(TableColumnModelEvent e) {
- if (this.isEditing()) {
- this.removeEditor();
- }
-
- this.resizeAndRepaint();
- }
-
- public int columnAtPoint(Point point) {
- return this.getColumnModel().getColumnIndexAtX(point.x);
- }
-
- public void columnMarginChanged(ChangeEvent e) {
- if (this.isEditing()) {
- this.removeEditor();
- }
-
- this.resizeAndRepaint();
- }
-
- public void columnMoved(TableColumnModelEvent e) {
- if (this.isEditing()) {
- this.removeEditor();
- }
-
- ((Component)this).repaint();
- }
-
- public void columnRemoved(TableColumnModelEvent e) {
- if (this.isEditing()) {
- this.removeEditor();
- }
-
- this.resizeAndRepaint();
- }
-
- public void columnSelectionChanged(ListSelectionEvent e) {
- int firstIndex = e.getFirstIndex();
- int lastIndex = e.getLastIndex();
- if (firstIndex == -1 && lastIndex == -1) {
- ((Component)this).repaint();
- }
-
- Rectangle firstColumnRect = this.getCellRect(0, firstIndex, false);
- Rectangle lastColumnRect = this.getCellRect(this.getRowCount(), lastIndex, false);
- Rectangle dirtyRegion = firstColumnRect.union(lastColumnRect);
- ((Component)this).repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
- }
-
- protected void configureEnclosingScrollPane() {
- Container p = ((Component)this).getParent();
- if (p instanceof JViewport) {
- Container gp = ((Component)p).getParent();
- if (gp instanceof JScrollPane) {
- JScrollPane scrollPane = (JScrollPane)gp;
- JViewport viewport = scrollPane.getViewport();
- if (viewport == null || viewport.getView() != this) {
- return;
- }
-
- scrollPane.setColumnHeaderView(this.getTableHeader());
- scrollPane.getViewport().setBackingStoreEnabled(true);
- ((JComponent)scrollPane).setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
- }
- }
-
- }
-
- public int convertColumnIndexToModel(int viewColumnIndex) {
- return viewColumnIndex < 0 ? viewColumnIndex : this.getColumnModel().getColumn(viewColumnIndex).getModelIndex();
- }
-
- public int convertColumnIndexToView(int modelColumnIndex) {
- if (modelColumnIndex < 0) {
- return modelColumnIndex;
- } else {
- TableColumnModel cm = this.getColumnModel();
-
- for(int column = 0; column < this.getColumnCount(); ++column) {
- if (cm.getColumn(column).getModelIndex() == modelColumnIndex) {
- return column;
- }
- }
-
- return -1;
- }
- }
-
- protected TableColumnModel createDefaultColumnModel() {
- return new DefaultTableColumnModel();
- }
-
- public void createDefaultColumnsFromModel() {
- TableModel m = this.getModel();
- if (m != null) {
- TableColumnModel cm = this.getColumnModel();
- cm.removeColumnModelListener(this);
-
- while(cm.getColumnCount() > 0) {
- cm.removeColumn(cm.getColumn(0));
- }
-
- for(int i = 0; i < m.getColumnCount(); ++i) {
- TableColumn newColumn = new TableColumn(i);
- this.addColumn(newColumn);
- }
-
- cm.addColumnModelListener(this);
- }
-
- }
-
- protected TableModel createDefaultDataModel() {
- return new DefaultTableModel();
- }
-
- protected void createDefaultEditors() {
- this.defaultEditorsByColumnClass = new Hashtable();
- JTextField textField = new JTextField();
- ((JComponent)textField).setBorder(new LineBorder(Color.black));
- Class var10001 = class$java$lang$Object;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Object");
- } catch (ClassNotFoundException var6) {
- throw new NoClassDefFoundError(((Throwable)var6).getMessage());
- }
-
- class$java$lang$Object = var10001;
- }
-
- this.setDefaultEditor(var10001, new DefaultCellEditor(textField));
- JTextField rightAlignedTextField = new JTextField();
- rightAlignedTextField.setHorizontalAlignment(4);
- ((JComponent)rightAlignedTextField).setBorder(new LineBorder(Color.black));
- var10001 = class$java$lang$Number;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Number");
- } catch (ClassNotFoundException var5) {
- throw new NoClassDefFoundError(((Throwable)var5).getMessage());
- }
-
- class$java$lang$Number = var10001;
- }
-
- this.setDefaultEditor(var10001, new DefaultCellEditor(rightAlignedTextField));
- JCheckBox centeredCheckBox = new JCheckBox();
- ((AbstractButton)centeredCheckBox).setHorizontalAlignment(0);
- var10001 = class$java$lang$Boolean;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Boolean");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$java$lang$Boolean = var10001;
- }
-
- this.setDefaultEditor(var10001, new DefaultCellEditor(centeredCheckBox));
- }
-
- protected void createDefaultRenderers() {
- this.defaultRenderersByColumnClass = new Hashtable();
- DefaultTableCellRenderer label = new DefaultTableCellRenderer();
- Class var10001 = class$java$lang$Object;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Object");
- } catch (ClassNotFoundException var8) {
- throw new NoClassDefFoundError(((Throwable)var8).getMessage());
- }
-
- class$java$lang$Object = var10001;
- }
-
- this.setDefaultRenderer(var10001, label);
- DefaultTableCellRenderer rightAlignedLabel = new DefaultTableCellRenderer();
- ((JLabel)rightAlignedLabel).setHorizontalAlignment(4);
- var10001 = class$java$lang$Number;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Number");
- } catch (ClassNotFoundException var7) {
- throw new NoClassDefFoundError(((Throwable)var7).getMessage());
- }
-
- class$java$lang$Number = var10001;
- }
-
- this.setDefaultRenderer(var10001, rightAlignedLabel);
- DefaultTableCellRenderer centeredLabel = new 3();
- ((JLabel)centeredLabel).setHorizontalAlignment(0);
- var10001 = class$com$sun$java$swing$ImageIcon;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("com.sun.java.swing.ImageIcon");
- } catch (ClassNotFoundException var6) {
- throw new NoClassDefFoundError(((Throwable)var6).getMessage());
- }
-
- class$com$sun$java$swing$ImageIcon = var10001;
- }
-
- this.setDefaultRenderer(var10001, centeredLabel);
- CheckBoxRenderer booleanRenderer = new CheckBoxRenderer(this);
- ((AbstractButton)booleanRenderer).setHorizontalAlignment(0);
- var10001 = class$java$lang$Boolean;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.lang.Boolean");
- } catch (ClassNotFoundException var5) {
- throw new NoClassDefFoundError(((Throwable)var5).getMessage());
- }
-
- class$java$lang$Boolean = var10001;
- }
-
- this.setDefaultRenderer(var10001, booleanRenderer);
- }
-
- protected ListSelectionModel createDefaultSelectionModel() {
- DefaultListSelectionModel m = new DefaultListSelectionModel();
- m.setLeadAnchorNotificationEnabled(false);
- return m;
- }
-
- protected JTableHeader createDefaultTableHeader() {
- return new JTableHeader(this.columnModel);
- }
-
- /** @deprecated */
- public static JScrollPane createScrollPaneForTable(JTable aTable) {
- return new JScrollPane(aTable);
- }
-
- public boolean editCellAt(int row, int column) {
- return this.editCellAt(row, column, (EventObject)null);
- }
-
- public boolean editCellAt(int row, int column, EventObject e) {
- if (!this.isCellEditable(row, column)) {
- return false;
- } else {
- if (this.isEditing() && this.cellEditor != null) {
- boolean stopped = this.cellEditor.stopCellEditing();
- if (!stopped) {
- return false;
- }
- }
-
- TableColumn tableColumn = this.getColumnModel().getColumn(column);
- TableCellEditor editor = tableColumn.getCellEditor();
- if (editor == null) {
- editor = this.getDefaultEditor(this.getColumnClass(column));
- }
-
- if (editor != null) {
- this.editorComp = this.prepareEditor(editor, row, column);
- if (editor.isCellEditable(e)) {
- this.editorComp.setBounds(this.getCellRect(row, column, false));
- ((Container)this).add(this.editorComp);
- this.editorComp.validate();
- editor.shouldSelectCell(e);
- this.setCellEditor(editor);
- this.setEditingRow(row);
- this.setEditingColumn(column);
- editor.addCellEditorListener(this);
- ((Component)this).repaint();
- return true;
- }
- }
-
- return false;
- }
- }
-
- public void editingCanceled(ChangeEvent e) {
- this.removeEditor();
- }
-
- public void editingStopped(ChangeEvent e) {
- TableCellEditor editor = this.getCellEditor();
- if (editor != null) {
- Object value = editor.getCellEditorValue();
- this.setValueAt(value, this.editingRow, this.editingColumn);
- this.removeEditor();
- }
-
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJTable(this);
- }
-
- return super.accessibleContext;
- }
-
- public boolean getAutoCreateColumnsFromModel() {
- return this.autoCreateColumnsFromModel;
- }
-
- public int getAutoResizeMode() {
- return this.autoResizeMode;
- }
-
- public TableCellEditor getCellEditor() {
- return this.cellEditor;
- }
-
- public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
- int index = 0;
- int columnMargin = this.getColumnModel().getColumnMargin();
- Enumeration enumeration = this.getColumnModel().getColumns();
- Rectangle cellFrame = new Rectangle();
- cellFrame.height = this.getRowHeight() + this.rowMargin;
-
- for(cellFrame.y = row * cellFrame.height; enumeration.hasMoreElements(); ++index) {
- TableColumn aColumn = (TableColumn)enumeration.nextElement();
- cellFrame.width = aColumn.getWidth() + columnMargin;
- if (index == column) {
- break;
- }
-
- cellFrame.x += cellFrame.width;
- }
-
- if (!includeSpacing) {
- Dimension spacing = this.getIntercellSpacing();
- cellFrame.setBounds(cellFrame.x + spacing.width / 2, cellFrame.y + spacing.height / 2, cellFrame.width - spacing.width, cellFrame.height - spacing.height);
- }
-
- return cellFrame;
- }
-
- public boolean getCellSelectionEnabled() {
- return this.cellSelectionEnabled;
- }
-
- public TableColumn getColumn(Object identifier) {
- TableColumnModel cm = this.getColumnModel();
- int columnIndex = cm.getColumnIndex(identifier);
- return cm.getColumn(columnIndex);
- }
-
- public Class getColumnClass(int column) {
- return this.getModel().getColumnClass(this.convertColumnIndexToModel(column));
- }
-
- public int getColumnCount() {
- return this.getColumnModel().getColumnCount();
- }
-
- public TableColumnModel getColumnModel() {
- return this.columnModel;
- }
-
- public String getColumnName(int column) {
- return this.getModel().getColumnName(this.convertColumnIndexToModel(column));
- }
-
- public boolean getColumnSelectionAllowed() {
- return this.columnModel.getColumnSelectionAllowed();
- }
-
- public TableCellEditor getDefaultEditor(Class columnClass) {
- if (columnClass == null) {
- return null;
- } else {
- Object editor = this.defaultEditorsByColumnClass.get(columnClass);
- return editor != null ? (TableCellEditor)editor : this.getDefaultEditor(columnClass.getSuperclass());
- }
- }
-
- public TableCellRenderer getDefaultRenderer(Class columnClass) {
- if (columnClass == null) {
- return null;
- } else {
- Object renderer = this.defaultRenderersByColumnClass.get(columnClass);
- return renderer != null ? (TableCellRenderer)renderer : this.getDefaultRenderer(columnClass.getSuperclass());
- }
- }
-
- public int getEditingColumn() {
- return this.editingColumn;
- }
-
- public int getEditingRow() {
- return this.editingRow;
- }
-
- public Component getEditorComponent() {
- return this.editorComp;
- }
-
- public Color getGridColor() {
- return this.gridColor;
- }
-
- public Dimension getIntercellSpacing() {
- return new Dimension(this.getColumnModel().getColumnMargin(), this.rowMargin);
- }
-
- public TableModel getModel() {
- return this.dataModel;
- }
-
- public Dimension getPreferredScrollableViewportSize() {
- return this.preferredViewportSize;
- }
-
- public int getRowCount() {
- return this.getModel().getRowCount();
- }
-
- public int getRowHeight() {
- return this.rowHeight;
- }
-
- public boolean getRowSelectionAllowed() {
- return this.rowSelectionAllowed;
- }
-
- public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
- return orientation == 1 ? visibleRect.height : visibleRect.width;
- }
-
- public boolean getScrollableTracksViewportHeight() {
- return false;
- }
-
- public boolean getScrollableTracksViewportWidth() {
- return false;
- }
-
- public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
- return orientation == 0 ? 1 : this.rowHeight;
- }
-
- public int getSelectedColumn() {
- return this.columnModel.getSelectionModel().getAnchorSelectionIndex();
- }
-
- public int getSelectedColumnCount() {
- return this.columnModel.getSelectedColumnCount();
- }
-
- public int[] getSelectedColumns() {
- return this.columnModel.getSelectedColumns();
- }
-
- public int getSelectedRow() {
- return this.selectionModel != null ? this.selectionModel.getAnchorSelectionIndex() : -1;
- }
-
- public int getSelectedRowCount() {
- if (this.selectionModel != null) {
- int iMin = this.selectionModel.getMinSelectionIndex();
- int iMax = this.selectionModel.getMaxSelectionIndex();
- int count = 0;
-
- for(int i = iMin; i <= iMax; ++i) {
- if (this.selectionModel.isSelectedIndex(i)) {
- ++count;
- }
- }
-
- return count;
- } else {
- return 0;
- }
- }
-
- public int[] getSelectedRows() {
- if (this.selectionModel != null) {
- int iMin = this.selectionModel.getMinSelectionIndex();
- int iMax = this.selectionModel.getMaxSelectionIndex();
- if (iMin != -1 && iMax != -1) {
- int[] rvTmp = new int[1 + (iMax - iMin)];
- int n = 0;
-
- for(int i = iMin; i <= iMax; ++i) {
- if (this.selectionModel.isSelectedIndex(i)) {
- rvTmp[n++] = i;
- }
- }
-
- int[] rv = new int[n];
- System.arraycopy(rvTmp, 0, rv, 0, n);
- return rv;
- } else {
- return new int[0];
- }
- } else {
- return new int[0];
- }
- }
-
- public Color getSelectionBackground() {
- return this.selectionBackground;
- }
-
- public Color getSelectionForeground() {
- return this.selectionForeground;
- }
-
- public ListSelectionModel getSelectionModel() {
- return this.selectionModel;
- }
-
- public boolean getShowHorizontalLines() {
- return this.showHorizontalLines;
- }
-
- public boolean getShowVerticalLines() {
- return this.showVerticalLines;
- }
-
- public JTableHeader getTableHeader() {
- return this.tableHeader;
- }
-
- public String getToolTipText(MouseEvent event) {
- String tip = null;
- Point p = event.getPoint();
- int hitColumnIndex = this.columnAtPoint(p);
- int hitRowIndex = this.rowAtPoint(p);
- if (hitColumnIndex != -1 && hitRowIndex != -1) {
- TableColumn aColumn = this.getColumnModel().getColumn(hitColumnIndex);
- TableCellRenderer renderer = aColumn.getCellRenderer();
- if (renderer == null) {
- Class columnClass = this.getColumnClass(hitColumnIndex);
- renderer = this.getDefaultRenderer(columnClass);
- }
-
- Component component = renderer.getTableCellRendererComponent(this, (Object)null, false, false, hitRowIndex, hitColumnIndex);
- if (component instanceof JComponent) {
- Rectangle cellRect = this.getCellRect(hitRowIndex, hitColumnIndex, false);
- p.translate(-cellRect.x, -cellRect.y);
- MouseEvent newEvent = new MouseEvent(component, ((AWTEvent)event).getID(), ((InputEvent)event).getWhen(), ((InputEvent)event).getModifiers(), p.x, p.y, event.getClickCount(), event.isPopupTrigger());
- tip = ((JComponent)component).getToolTipText(newEvent);
- }
- }
-
- if (tip == null) {
- tip = ((JComponent)this).getToolTipText();
- }
-
- return tip;
- }
-
- public TableUI getUI() {
- return (TableUI)super.ui;
- }
-
- public String getUIClassID() {
- return "TableUI";
- }
-
- public Object getValueAt(int row, int column) {
- return this.getModel().getValueAt(row, this.convertColumnIndexToModel(column));
- }
-
- protected void initializeLocalVars() {
- this.createDefaultRenderers();
- this.createDefaultEditors();
- this.setTableHeader(this.createDefaultTableHeader());
- this.setShowGrid(true);
- this.setAutoResizeMode(2);
- this.setRowHeight(16);
- this.rowMargin = 1;
- this.setSelectionMode(2);
- this.setColumnSelectionAllowed(false);
- this.setRowSelectionAllowed(true);
- this.setCellSelectionEnabled(false);
- this.cellEditor = null;
- this.editingColumn = this.editingRow = -1;
- this.preferredViewportSize = new Dimension(450, 400);
- ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
- toolTipManager.registerComponent(this);
- ((JComponent)this).setAutoscrolls(true);
- this.tableHeader.setAutoscrolls(true);
- }
-
- public boolean isCellEditable(int row, int column) {
- return this.getModel().isCellEditable(row, this.convertColumnIndexToModel(column));
- }
-
- public boolean isCellSelected(int row, int column) {
- if (this.cellSelectionEnabled) {
- return this.isRowSelected(row) && this.isColumnSelected(column);
- } else {
- return this.getRowSelectionAllowed() && this.isRowSelected(row) || this.getColumnSelectionAllowed() && this.isColumnSelected(column);
- }
- }
-
- public boolean isColumnSelected(int column) {
- return this.columnModel.getSelectionModel().isSelectedIndex(column);
- }
-
- public boolean isEditing() {
- return this.cellEditor != null;
- }
-
- public boolean isOpaque() {
- return true;
- }
-
- public boolean isRowSelected(int row) {
- return this.selectionModel != null ? this.selectionModel.isSelectedIndex(row) : false;
- }
-
- public void moveColumn(int column, int targetColumn) {
- this.getColumnModel().moveColumn(column, targetColumn);
- }
-
- public Component prepareEditor(TableCellEditor editor, int row, int column) {
- Object value = this.getValueAt(row, column);
- this.getColumnModel().getColumn(column);
- boolean isSelected = this.isCellSelected(row, column);
- Component comp = editor.getTableCellEditorComponent(this, value, isSelected, row, column);
- if (comp != null && comp.getFont() == null) {
- comp.setFont(((Component)this).getFont());
- }
-
- return comp;
- }
-
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
- s.defaultReadObject();
- this.createDefaultRenderers();
- this.createDefaultEditors();
- }
-
- public void removeColumn(TableColumn aColumn) {
- this.getColumnModel().removeColumn(aColumn);
- }
-
- public void removeColumnSelectionInterval(int index0, int index1) {
- this.columnModel.getSelectionModel().removeSelectionInterval(index0, index1);
- }
-
- public void removeEditor() {
- TableCellEditor editor = this.getCellEditor();
- if (editor != null) {
- editor.removeCellEditorListener(this);
- if (this.editorComp instanceof JComboBox) {
- ((JComboBox)this.editorComp).hidePopup();
- }
-
- ((Container)this).remove(this.editorComp);
- Rectangle cellRect = this.getCellRect(this.editingRow, this.editingColumn, false);
- ((Component)this).repaint(cellRect.x, cellRect.y, cellRect.width, cellRect.height);
- if (!(this.editorComp instanceof JComponent) || ((JComponent)this.editorComp).hasFocus()) {
- ((JComponent)this).requestFocus();
- }
-
- this.setCellEditor((TableCellEditor)null);
- this.setEditingColumn(-1);
- this.setEditingRow(-1);
- this.editorComp = null;
- }
-
- }
-
- public void removeRowSelectionInterval(int index0, int index1) {
- this.selectionModel.removeSelectionInterval(index0, index1);
- }
-
- protected void resizeAndRepaint() {
- ((JComponent)this).revalidate();
- ((Component)this).repaint();
- }
-
- public int rowAtPoint(Point point) {
- int y = point.y;
- int rowHeight = this.getRowHeight();
- int rowSpacing = this.getIntercellSpacing().height;
- int totalRowHeight = rowHeight + rowSpacing;
- int result = y / totalRowHeight;
- if (result < 0) {
- return -1;
- } else {
- return result >= this.getRowCount() ? -1 : result;
- }
- }
-
- public void selectAll() {
- if (this.getSelectedRowCount() > 0) {
- int count = this.getRowCount();
- if (count > 0) {
- this.setRowSelectionInterval(0, count);
- }
- }
-
- if (this.getSelectedColumnCount() > 0) {
- int count = this.getColumnCount();
- if (count > 0) {
- this.setColumnSelectionInterval(0, count);
- }
- }
-
- }
-
- public void setAutoCreateColumnsFromModel(boolean createColumns) {
- if (this.autoCreateColumnsFromModel != createColumns) {
- this.autoCreateColumnsFromModel = createColumns;
- if (this.autoCreateColumnsFromModel) {
- this.createDefaultColumnsFromModel();
- }
- }
-
- }
-
- public void setAutoResizeMode(int mode) {
- if (mode == 2 || mode == 1 || mode == 0) {
- this.autoResizeMode = mode;
- this.resizeAndRepaint();
- this.tableHeader.resizeAndRepaint();
- }
-
- }
-
- public void setCellEditor(TableCellEditor anEditor) {
- this.cellEditor = anEditor;
- }
-
- public void setCellSelectionEnabled(boolean flag) {
- this.clearSelection();
- this.cellSelectionEnabled = flag;
- }
-
- public void setColumnModel(TableColumnModel newModel) {
- if (newModel == null) {
- throw new IllegalArgumentException("Cannot set a null ColumnModel");
- } else {
- TableColumnModel oldModel = this.columnModel;
- if (newModel != oldModel) {
- if (oldModel != null) {
- oldModel.removeColumnModelListener(this);
- }
-
- this.columnModel = newModel;
- newModel.addColumnModelListener(this);
- if (this.tableHeader != null) {
- this.tableHeader.setColumnModel(newModel);
- }
-
- this.resizeAndRepaint();
- }
-
- }
- }
-
- public void setColumnSelectionAllowed(boolean flag) {
- this.clearSelection();
- this.columnModel.setColumnSelectionAllowed(flag);
- }
-
- public void setColumnSelectionInterval(int index0, int index1) {
- this.columnModel.getSelectionModel().setSelectionInterval(index0, index1);
- }
-
- public void setDefaultEditor(Class columnClass, TableCellEditor editor) {
- this.defaultEditorsByColumnClass.put(columnClass, editor);
- }
-
- public void setDefaultRenderer(Class columnClass, TableCellRenderer renderer) {
- this.defaultRenderersByColumnClass.put(columnClass, renderer);
- }
-
- public void setEditingColumn(int aColumn) {
- this.editingColumn = aColumn;
- }
-
- public void setEditingRow(int aRow) {
- this.editingRow = aRow;
- }
-
- public void setGridColor(Color newColor) {
- if (newColor == null) {
- throw new IllegalArgumentException("New color is null");
- } else {
- this.gridColor = newColor;
- ((Component)this).repaint();
- }
- }
-
- public void setIntercellSpacing(Dimension newSpacing) {
- this.rowMargin = newSpacing.height;
- this.getColumnModel().setColumnMargin(newSpacing.width);
- this.resizeAndRepaint();
- }
-
- public void setModel(TableModel newModel) {
- TableModel oldModel = this.dataModel;
- if (newModel == null) {
- throw new IllegalArgumentException("Cannot set a null TableModel");
- } else {
- if (newModel != oldModel) {
- if (oldModel != null) {
- oldModel.removeTableModelListener(this);
- }
-
- this.dataModel = newModel;
- newModel.addTableModelListener(this);
- if (this.getColumnModel() != null) {
- this.tableChanged(new TableModelEvent(this.dataModel, -1));
- }
- }
-
- }
- }
-
- public void setPreferredScrollableViewportSize(Dimension size) {
- this.preferredViewportSize = size;
- }
-
- public void setRowHeight(int newHeight) {
- if (newHeight <= 0) {
- throw new IllegalArgumentException("New row height less than 1");
- } else {
- this.rowHeight = newHeight;
- this.resizeAndRepaint();
- }
- }
-
- public void setRowSelectionAllowed(boolean flag) {
- this.clearSelection();
- this.rowSelectionAllowed = flag;
- }
-
- public void setRowSelectionInterval(int index0, int index1) {
- this.selectionModel.setSelectionInterval(index0, index1);
- }
-
- public void setSelectionBackground(Color selectionBackground) {
- Color oldValue = this.selectionBackground;
- this.selectionBackground = selectionBackground;
- ((JComponent)this).firePropertyChange("selectionBackground", oldValue, selectionBackground);
- }
-
- public void setSelectionForeground(Color selectionForeground) {
- Color oldValue = this.selectionForeground;
- this.selectionForeground = selectionForeground;
- ((JComponent)this).firePropertyChange("selectionForeground", oldValue, selectionForeground);
- }
-
- public void setSelectionMode(int selectionMode) {
- this.clearSelection();
- this.getSelectionModel().setSelectionMode(selectionMode);
- this.getColumnModel().getSelectionModel().setSelectionMode(selectionMode);
- }
-
- public void setSelectionModel(ListSelectionModel newModel) {
- if (newModel == null) {
- throw new IllegalArgumentException("Cannot set a null SelectionModel");
- } else {
- ListSelectionModel oldModel = this.selectionModel;
- if (newModel != oldModel) {
- if (oldModel != null) {
- oldModel.removeListSelectionListener(this);
- }
-
- this.selectionModel = newModel;
- if (newModel != null) {
- newModel.addListSelectionListener(this);
- }
-
- ((Component)this).repaint();
- }
-
- }
- }
-
- public void setShowGrid(boolean b) {
- this.setShowHorizontalLines(b);
- this.setShowVerticalLines(b);
- ((Component)this).repaint();
- }
-
- public void setShowHorizontalLines(boolean b) {
- this.showHorizontalLines = b;
- ((Component)this).repaint();
- }
-
- public void setShowVerticalLines(boolean b) {
- this.showVerticalLines = b;
- ((Component)this).repaint();
- }
-
- public void setTableHeader(JTableHeader newHeader) {
- if (this.tableHeader != newHeader) {
- if (this.tableHeader != null) {
- this.tableHeader.setTable((JTable)null);
- }
-
- this.tableHeader = newHeader;
- if (this.tableHeader != null) {
- this.tableHeader.setTable(this);
- }
- }
-
- }
-
- public void setUI(TableUI ui) {
- if (super.ui != ui) {
- super.setUI(ui);
- ((Component)this).repaint();
- }
-
- }
-
- public void setValueAt(Object aValue, int row, int column) {
- this.getModel().setValueAt(aValue, row, this.convertColumnIndexToModel(column));
- }
-
- public void sizeColumnsToFit(boolean lastColumnOnly) {
- int intercellWidth = this.getColumnModel().getColumnMargin();
- int frameWidth = ((JComponent)this).getWidth();
- int totalColumnWidth = 0;
- int index = 0;
- int[] columnWidths = new int[this.getColumnCount()];
- int[] columnMaxWidths = new int[this.getColumnCount()];
- int[] columnMinWidths = new int[this.getColumnCount()];
-
- for(Enumeration enumeration = this.getColumnModel().getColumns(); enumeration.hasMoreElements(); ++index) {
- TableColumn aColumn = (TableColumn)enumeration.nextElement();
- columnWidths[index] = aColumn.getWidth();
- columnMaxWidths[index] = aColumn.getMaxWidth();
- columnMinWidths[index] = aColumn.getMinWidth();
- totalColumnWidth += aColumn.getWidth() + intercellWidth;
- }
-
- int delta = frameWidth - totalColumnWidth;
- if (-1 > delta || delta > 1) {
- if (lastColumnOnly) {
- for(int var19 = this.getColumnCount() - 1; var19 >= 0; --var19) {
- int maxColumnDelta;
- if (delta > 0) {
- maxColumnDelta = columnMaxWidths[var19] - columnWidths[var19];
- } else {
- maxColumnDelta = columnMinWidths[var19] - columnWidths[var19];
- }
-
- if (Math.abs(maxColumnDelta) >= Math.abs(delta)) {
- columnWidths[var19] += delta;
- break;
- }
-
- columnWidths[var19] += maxColumnDelta;
- delta -= maxColumnDelta;
- }
- } else {
- float[] percentShare = new float[this.getColumnCount()];
- boolean stillHaveRoom = true;
-
- for(int var20 = 0; var20 < this.getColumnCount(); ++var20) {
- percentShare[var20] = (float)(columnWidths[var20] + intercellWidth) / (float)totalColumnWidth;
- }
-
- while(delta != 0 && stillHaveRoom) {
- int deltaRemainder = delta;
- stillHaveRoom = false;
-
- for(int var21 = 0; var21 < this.getColumnCount(); ++var21) {
- int shareDelta = (int)Math.ceil((double)((float)delta * percentShare[var21]));
- if (deltaRemainder == 0) {
- break;
- }
-
- if (Math.abs(deltaRemainder) < Math.abs(shareDelta)) {
- shareDelta = deltaRemainder;
- }
-
- int var25;
- if (shareDelta > 0) {
- var25 = columnMaxWidths[var21] - columnWidths[var21];
- } else {
- if (shareDelta >= 0) {
- continue;
- }
-
- var25 = columnMinWidths[var21] - columnWidths[var21];
- }
-
- if (Math.abs(var25) >= Math.abs(shareDelta)) {
- stillHaveRoom = true;
- columnWidths[var21] += shareDelta;
- deltaRemainder -= shareDelta;
- } else if (var25 != 0) {
- columnWidths[var21] += var25;
- deltaRemainder -= var25;
- percentShare[var21] = 0.0F;
- }
- }
-
- delta = deltaRemainder;
- if (deltaRemainder != 0) {
- float percentLeft = 0.0F;
-
- for(int var22 = 0; var22 < this.getColumnCount(); ++var22) {
- percentLeft += percentShare[var22];
- }
-
- float var27 = 100.0F / percentLeft;
-
- for(int var23 = 0; var23 < this.getColumnCount(); ++var23) {
- percentShare[var23] *= var27;
- }
- }
- }
- }
-
- index = 0;
-
- for(Enumeration var26 = this.getColumnModel().getColumns(); var26.hasMoreElements(); ++index) {
- TableColumn var18 = (TableColumn)var26.nextElement();
- var18.setWidth(columnWidths[index]);
- }
-
- }
- }
-
- public void tableChanged(TableModelEvent e) {
- if (e != null && e.getFirstRow() != -1) {
- if (e.getType() == 1) {
- this.tableRowsInserted(e);
- } else if (e.getType() == -1) {
- this.tableRowsDeleted(e);
- } else {
- int modelColumn = e.getColumn();
- int start = e.getFirstRow();
- int end = e.getLastRow();
- if (start == -1) {
- start = 0;
- end = Integer.MAX_VALUE;
- }
-
- int rowHeight = this.getRowHeight() + this.rowMargin;
- Rectangle dirtyRegion;
- if (modelColumn == -1) {
- dirtyRegion = new Rectangle(0, start * rowHeight, this.getColumnModel().getTotalColumnWidth(), 0);
- } else {
- int column = this.convertColumnIndexToView(modelColumn);
- dirtyRegion = this.getCellRect(start, column, false);
- }
-
- if (end != Integer.MAX_VALUE) {
- dirtyRegion.height = (end - start + 1) * rowHeight;
- ((Component)this).repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
- } else {
- this.resizeAndRepaint();
- }
-
- }
- } else {
- this.clearSelection();
- if (this.getAutoCreateColumnsFromModel()) {
- this.createDefaultColumnsFromModel();
- }
-
- this.resizeAndRepaint();
- if (this.tableHeader != null) {
- this.tableHeader.resizeAndRepaint();
- }
-
- }
- }
-
- private void tableRowsDeleted(TableModelEvent e) {
- int start = e.getFirstRow();
- if (start < 0) {
- start = 0;
- }
-
- int rowHeight = this.getRowHeight() + this.rowMargin;
- Rectangle drawRect = new Rectangle(0, start * rowHeight, this.getColumnModel().getTotalColumnWidth(), (this.getRowCount() - start) * rowHeight);
- if (this.selectionModel != null) {
- int end = e.getLastRow();
- if (end < 0) {
- end = this.getRowCount() - 1;
- }
-
- this.selectionModel.removeIndexInterval(start, end);
- }
-
- ((JComponent)this).revalidate();
- ((Component)this).repaint(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
- }
-
- private void tableRowsInserted(TableModelEvent e) {
- int start = e.getFirstRow();
- if (start < 0) {
- start = 0;
- }
-
- int rowHeight = this.getRowHeight() + this.rowMargin;
- Rectangle drawRect = new Rectangle(0, start * rowHeight, this.getColumnModel().getTotalColumnWidth(), (this.getRowCount() - start) * rowHeight);
- if (this.selectionModel != null) {
- int end = e.getLastRow();
- if (end < 0) {
- end = this.getRowCount() - 1;
- }
-
- int length = end - start + 1;
- this.selectionModel.insertIndexInterval(start, length, true);
- }
-
- ((JComponent)this).revalidate();
- ((Component)this).repaint(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
- }
-
- private void updateSubComponentUI(Object componentShell) {
- if (componentShell != null) {
- Component component = null;
- if (componentShell instanceof Component) {
- component = (Component)componentShell;
- }
-
- if (componentShell instanceof DefaultCellEditor) {
- component = ((DefaultCellEditor)componentShell).getComponent();
- }
-
- if (component != null && component instanceof JComponent) {
- ((JComponent)component).updateUI();
- }
-
- }
- }
-
- public void updateUI() {
- TableColumnModel cm = this.getColumnModel();
-
- for(int column = 0; column < cm.getColumnCount(); ++column) {
- TableColumn aColumn = cm.getColumn(column);
- this.updateSubComponentUI(aColumn.getCellEditor());
- }
-
- Enumeration defaultEditors = this.defaultEditorsByColumnClass.elements();
-
- while(defaultEditors.hasMoreElements()) {
- this.updateSubComponentUI(defaultEditors.nextElement());
- }
-
- this.setUI((TableUI)UIManager.getUI(this));
- this.resizeAndRepaint();
- ((Container)this).invalidate();
- }
-
- public void valueChanged(ListSelectionEvent e) {
- int firstIndex = e.getFirstIndex();
- int lastIndex = e.getLastIndex();
- if (firstIndex == -1 && lastIndex == -1) {
- ((Component)this).repaint();
- }
-
- Rectangle firstRowRect = this.getCellRect(firstIndex, 0, false);
- Rectangle lastRowRect = this.getCellRect(lastIndex, this.getColumnCount(), false);
- Rectangle dirtyRegion = firstRowRect.union(lastRowRect);
- ((Component)this).repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
- }
-
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.defaultWriteObject();
- }
- }
-